home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / exkey4.arc / EXTKEY.ASM < prev    next >
Assembly Source File  |  1990-01-27  |  5KB  |  169 lines

  1.  
  2. ;┌────────────────────────────────────────────────────────────────────┐
  3. ;│ EXTKEY.ASM - INT 16 handler to deal with extended AT keyboard      │
  4. ;│                                      │
  5. ;│ This routine tests for the presence of an extended 101 or 102      │
  6. ;│ key keyboard. If the extended keyboard is detected then this       │
  7. ;│ routine causes any INT 16 calls to invokes the enhanced keyboard   │
  8. ;│ handler functions by default instead of the standard routines.     │
  9. ;│                                      │
  10. ;│ Originally designed for use with Turbo Pascal, though the routines │
  11. ;│ may be called by any package as they need no parameters. To use    │
  12. ;│ these routines simply call the function SetKeyVector at the start  │
  13. ;│ of your program, and call RestoreKeyVector before leaving. The     │
  14. ;│ rest is automatic.                              │
  15. ;│                                      │
  16. ;│ (C) Copyright Aubrey Scoon 1990                      │
  17. ;│                                      │
  18. ;│ Scoon Consultancy Services                          │
  19. ;│ 49 Honeyhill Road,                              │
  20. ;│ Bracknell,                                  │
  21. ;│ Berkshire.                                  │
  22. ;│ RG12 1YH.                                  │
  23. ;│ U.K.                                   │
  24. ;│                                      │
  25. ;└────────────────────────────────────────────────────────────────────┘
  26.  
  27. code      segment   byte      public
  28.  
  29.       assume    cs:code
  30.  
  31.       public    SetKeyVector,RestoreKeyVector,Ext_Keyboard_Present
  32.  
  33. ;─────────────────────────────────────────────────────────────────────
  34.  
  35. SetKeyVector   proc     far
  36.  
  37. ; Install new interrupt handler
  38.  
  39.  
  40.       mov        ah,35h             ; get interrupt vector
  41.       mov        al,16h             ; vector to get
  42.       int        21h              ; DOS call
  43.  
  44.       mov        ax,es             ; vector segment
  45.       mov        cs:vectseg,ax         ; store it
  46.       mov        cs:vectofs,bx         ; store vector offset
  47.  
  48.       push        ds                 ; save data segment
  49.       mov        ax,cs
  50.       mov        ds,ax             ; set current segment
  51.       mov        dx,offset newkey
  52.       mov        ah,25h             ; set interrupt vector
  53.       mov        al,16h             ; vector to set
  54.       int        21h
  55.       pop        ds
  56.  
  57.       ret
  58.  
  59. ; Temporary storage for old interrupt vector
  60.  
  61. vectofs   dw        0
  62. vectseg   dw        0
  63.  
  64. ;─────────────────────────────────────────────────────────────────────
  65.  
  66. ; This is the actual new interrupt handler
  67.  
  68.  
  69. ; First check the function number
  70.  
  71. newkey:
  72.       push        ds                 ; store data segment
  73.       push        ax                 ; keep function params
  74.  
  75.       sti                     ; restart interrupts
  76.  
  77.       cmp        ah,03h            ; check function
  78.       jae        oldvect            ; if ah>=3 then call old vector
  79.  
  80. ; Function affected so check keyboard
  81.  
  82.       mov        ax,0040h             ; BIOS data segment
  83.       mov        ds,ax
  84.       mov        al,byte ptr ds:[0096h]   ; get keyboard state flags
  85.       and        al,10h             ; mask extended flag
  86.       jz        oldvect             ; must be old keyboard
  87.  
  88. ; If we get to here the machine has probably got an extended keyboard
  89. ; so we add 10h to the BIOS function number and call the old vector
  90.  
  91.  
  92. newcall:  pop        ax                 ; get old function no
  93.       add        ah,10h             ; modify function no
  94.       cmp        ah,12h             ; function 12h ?
  95.       je        ovect2             ; use enhanced function
  96.  
  97.       cli
  98.       pushf                  ; simulate interrupt
  99.       call        dword ptr cs:[vectofs]   ; do INT 16h !
  100.  
  101.       pushf                  ; save result flags
  102.       cmp        al,224             ; special key ?
  103.       jne        exit             ; no so quit
  104.       cmp        ah,0             ; fix for special keys
  105.       je        exit
  106.       mov        al,0
  107.  
  108. exit:      popf                     ; get result flags
  109.       pop        ds                 ; restore from stack
  110.  
  111.       sti                     ; restart interrupts
  112.       iret                     ; end of interrupt
  113.  
  114.  
  115. oldvect:  pop        ax                 ; pop function no
  116.  
  117. ovect2:   cli                     ; disable interrupts
  118.       pop        ds                 ; restore data segment
  119.       jmp        dword ptr cs:[vectofs]   ; jump to old vector
  120.  
  121.  
  122. SetkeyVector   endp
  123.  
  124. ;─────────────────────────────────────────────────────────────────────
  125.  
  126. RestoreKeyVector    proc      far
  127.  
  128. ; procedure to restore interrupt vector
  129.  
  130.       push        ds
  131.       mov        ax,seg SetKeyVector
  132.       mov        ds,ax
  133.       mov        dx,vectofs
  134.       mov        ax,vectseg             ; get old vector
  135.       mov        ds,ax
  136.       mov        ah,25h             ; set interrupt vector
  137.       mov        al,16h             ; interrupt number
  138.       int        21h              ; DOS call
  139.       pop        ds
  140.  
  141.       ret
  142.  
  143. RestoreKeyVector    endp
  144.  
  145. ;─────────────────────────────────────────────────────────────────────
  146.  
  147. Ext_Keyboard_Present     proc far
  148.  
  149. ; Returns boolean flag to indicate presence of enhanced keyboard
  150.  
  151.       push        es
  152.       mov        ax,0040h             ; BIOS data segment
  153.       mov        es,ax
  154.       mov        al,byte ptr es:[0096h]   ; get keyboard state flags
  155.       pop        es
  156.       and        al,10h             ; mask extended flag
  157.       jz        fin              ; must be old keyboard
  158.       mov        al,1
  159. fin:      ret
  160.  
  161. Ext_Keyboard_Present     endp
  162.  
  163. code      ends
  164.  
  165.       end
  166.  
  167. ;─────────────────────────────────────────────────────────────────────
  168. 
  169.